//
//  CJExten+Hosting.swift
//  CJPack
//
//  Created by chenjingwei on 2025/4/30.
//

import Foundation
import SwiftUI

public extension UIView {
    
    /// 添加UIHostingController
    func cj_addHosting<Content: View>(hc: UIHostingController<Content>) {
        hc.view.backgroundColor = .clear
        hc.view.frame = CGRect(
            x: 0,
            y: 0,
            width: cj_width,
            height: cj_height
        )
        addSubview(hc.view)
    }
}

public extension UIViewController {
    
    /// 添加UIHostingController
    func cj_addHosting<Content: View>(hc: UIHostingController<Content>) {
        hc.view.backgroundColor = .clear
        addChild(hc)
        hc.view.frame = CGRect(
            x: 0,
            y: CJScreen.navBatBarHeight,
            width: view.cj_width,
            height: view.cj_height_rbn
        )
        view.addSubview(hc.view)
        hc.didMove(toParent: self)
    }
    
}
